home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / gettext / intl / textdomain.c < prev    next >
Encoding:
C/C++ Source or Header  |  2010-09-19  |  3.8 KB  |  128 lines

  1. /* Implementation of the textdomain(3) function.
  2.    Copyright (C) 1995-1998, 2000-2003, 2005-2006 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify it
  5.    under the terms of the GNU Library General Public License as published
  6.    by the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public
  15.    License along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  17.    USA.  */
  18.  
  19. #ifdef HAVE_CONFIG_H
  20. # include <config.h>
  21. #endif
  22.  
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. #include "gettextP.h"
  27. #ifdef _LIBC
  28. # include <libintl.h>
  29. #else
  30. # include "libgnuintl.h"
  31. #endif
  32.  
  33. /* Handle multi-threaded applications.  */
  34. #ifdef _LIBC
  35. # include <bits/libc-lock.h>
  36. # define gl_rwlock_define __libc_rwlock_define
  37. # define gl_rwlock_wrlock __libc_rwlock_wrlock
  38. # define gl_rwlock_unlock __libc_rwlock_unlock
  39. #else
  40. # include "lock.h"
  41. #endif
  42.  
  43. /* @@ end of prolog @@ */
  44.  
  45.  
  46. /* Names for the libintl functions are a problem.  They must not clash
  47.    with existing names and they should follow ANSI C.  But this source
  48.    code is also used in GNU C Library where the names have a __
  49.    prefix.  So we have to make a difference here.  */
  50. #ifdef _LIBC
  51. # define TEXTDOMAIN __textdomain
  52. # ifndef strdup
  53. #  define strdup(str) __strdup (str)
  54. # endif
  55. #else
  56. # define TEXTDOMAIN libintl_textdomain
  57. #endif
  58.  
  59. /* Lock variable to protect the global data in the gettext implementation.  */
  60. gl_rwlock_define (extern, _nl_state_lock attribute_hidden)
  61.  
  62. /* Set the current default message catalog to DOMAINNAME.
  63.    If DOMAINNAME is null, return the current default.
  64.    If DOMAINNAME is "", reset to the default of "messages".  */
  65. char *
  66. TEXTDOMAIN (const char *domainname)
  67. {
  68.   char *new_domain;
  69.   char *old_domain;
  70.  
  71.   /* A NULL pointer requests the current setting.  */
  72.   if (domainname == NULL)
  73.     return (char *) _nl_current_default_domain;
  74.  
  75.   gl_rwlock_wrlock (_nl_state_lock);
  76.  
  77.   old_domain = (char *) _nl_current_default_domain;
  78.  
  79.   /* If domain name is the null string set to default domain "messages".  */
  80.   if (domainname[0] == '\0'
  81.       || strcmp (domainname, _nl_default_default_domain) == 0)
  82.     {
  83.       _nl_current_default_domain = _nl_default_default_domain;
  84.       new_domain = (char *) _nl_current_default_domain;
  85.     }
  86.   else if (strcmp (domainname, old_domain) == 0)
  87.     /* This can happen and people will use it to signal that some
  88.        environment variable changed.  */
  89.     new_domain = old_domain;
  90.   else
  91.     {
  92.       /* If the following malloc fails `_nl_current_default_domain'
  93.      will be NULL.  This value will be returned and so signals we
  94.      are out of core.  */
  95. #if defined _LIBC || defined HAVE_STRDUP
  96.       new_domain = strdup (domainname);
  97. #else
  98.       size_t len = strlen (domainname) + 1;
  99.       new_domain = (char *) malloc (len);
  100.       if (new_domain != NULL)
  101.     memcpy (new_domain, domainname, len);
  102. #endif
  103.  
  104.       if (new_domain != NULL)
  105.     _nl_current_default_domain = new_domain;
  106.     }
  107.  
  108.   /* We use this possibility to signal a change of the loaded catalogs
  109.      since this is most likely the case and there is no other easy we
  110.      to do it.  Do it only when the call was successful.  */
  111.   if (new_domain != NULL)
  112.     {
  113.       ++_nl_msg_cat_cntr;
  114.  
  115.       if (old_domain != new_domain && old_domain != _nl_default_default_domain)
  116.     free (old_domain);
  117.     }
  118.  
  119.   gl_rwlock_unlock (_nl_state_lock);
  120.  
  121.   return new_domain;
  122. }
  123.  
  124. #ifdef _LIBC
  125. /* Alias for function name in GNU C Library.  */
  126. weak_alias (__textdomain, textdomain);
  127. #endif
  128.